import request from '@/utils/request'
import type { PageParams } from '@/types/common'

// 说说相关接口类型定义
interface MomentForm {
  id?: string | number
  content: string
  location?: string
  images?: string[]
  userId: number
}

interface MomentQuery extends PageParams {
  content?: string
  location?: string
  startDate?: string
  endDate?: string
}

interface AddCommentParams {
  momentId: number | string
  content: string
  deviceName: string
  deviceInfo: string
  ipAddress: string
}

// 添加回复相关的接口
interface ReplyForm {
  content: string
  deviceName?: string
  isAdmin?: boolean
}

// API方法
export default {
  // 获取说说列表
  getMoments(params: MomentQuery) {
    return request.get('/moments', { params })
  },
  // 获取所有说说1列表
  getAllMoments() {
    return request.get('/momentsList')
  },


  // 新增说说
  addMoment(data: MomentForm) {
    return request.post('/moments', data)
  },

  // 编辑说说
  updateMoment(id: string | number, data: MomentForm) {
    return request.put(`/moments/${id}`, data)
  },

  // 删除说说
  deleteMoment(id: string | number) {
    return request.delete(`/moments/${id}`)
  },

  // 批量删除说说
  batchDeleteMoments(ids: (string | number)[]) {
    return request.delete('/moments/batch', { data: { ids } })
  },

  // 删除评论
  deleteComment(momentId: string | number, commentId: string | number) {
    return request.delete(`/moments/${momentId}/comments/${commentId}`)
  },

  // 添加点赞接口
  toggleLike(momentId: number | string) {
    return request.post(`/moments/${momentId}/like`)
  },

  getUserInfo: () => request.get('/user/info'),

  addComment(data: AddCommentParams) {
    return request.post(`/moments/${data.momentId}/comments`, data)
  },

  // 添加回复
  addReply(momentId: number | string, commentId: number | string, data: ReplyForm) {
    return request.post(`/moments/${momentId}/comments/${commentId}/reply`, data)
  },

  // 删除评论或回复
  deleteReply(commentId: number, replyId: number) {
    return request.delete(`/moments/comments/${commentId}/replies/${replyId}`)
  },

  // 获取评论的回复列表
  getReplies(commentId: number) {
    return request.get(`/moments/comments/${commentId}/replies`)
  }
} 